package com.sunlands.zlcx.usercenter.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sunlands.zlcx.usercenter.vo.AppErrorMessage;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @author anjl
 * @date 1:02 PM 2019/4/15
 * description:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "tz_app_system_message")
@DynamicUpdate
@DynamicInsert
public class AppSystemMessageDO implements Serializable {

    private static final long serialVersionUID = -2692947295426333346L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String msg;

    /**
     * 请求头信息
     */
    private String requestHeader;

    private Long userId;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /**
     * 修改时间
     */
    @UpdateTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;


    public static AppSystemMessageDO from(AppErrorMessage message) {
        return Objects.isNull(message) ? null :
                AppSystemMessageDO
                        .builder()
                        .msg(message.getMsg())
                        .build();
    }

}
